<?php
# !!!!!!!!!! DON'T MAKE ANY CHANGE IF YOU DON'T KNOW WHAT YOU'RE DOING !!!!!!!!!!
// --------------------------------------------------------------------------------------------------------------
// File Name              :	sendemail.php
// Last Modification Time	:	2008-02-01 24:00
// Last Modified by       :	turker (turker.biz@gmail.com)
// list of modifications  :
//
//	- 2008-02-01 turker
//		* 24:00 file created.
//
// --------------------------------------------------------------------------------------------------------------
############################################ E-MAIL MODÜLÜ ######################################################
#
# Tüm üyelere aynı e-postayı göndermek için kullanılır.
#
############################################ E-MAIL MODÜLÜ ######################################################

if (eregi("sendemail.php",$_SERVER['PHP_SELF'])) {
	header ("Location:../index.php");
	exit;
}

class sendEmailToMembers {
  var $users_table;

  function sendEmailToMembers() {
    global $USERS_TABLE;
    $this->users_table=$USERS_TABLE;
  }

  function showAdminLink() {
    global $SITE_URL;
    $r='echo\'<a href="'.$SITE_URL.'/index.php?page=module&module=sendemail" title="E-Mail Gönder">E-Mail Gönder</a><br />\';';
    return $r;
  }

  function showSendForm() {
    global $SITE_URL;
    $r='$module=@htmlspecialchars($_GET[\'module\']);
    if ($module==\'sendemail\') {
    echo \'
  <script type="text/javascript">
  $(document).ready(function(){
    $("#sendit").click(function(){
      $("#sendit").val(" Lütfen Bekleyiniz... ");
      $("#sendit").attr("disabled","disabled");
      var title=$.trim($("#title").val());
      var message=$.trim($("#message").val());
      if (title.length<3||title.length>55) {
        alert("Başlık en az 3 en fazla 55 karakter olmalıdır.");
        $("#title").focus();
      }
      else if (message.length<5) {
        alert("Mesaj en az 5 karekter olmalıdır.");
        $("#message").focus();
      }
      else {
        $("#sendmailForm").submit();
      }
      $("#sendit").val(" Gönder ");
      $("#sendit").attr("disabled","");
    });
  });
  </script>
    <h1>E-Posta Gönder</h1><br />
    <form id="sendmailForm" action="'.$SITE_URL.'/index.php?page=module&module=sendemail" method="post" class="box">
      <label>Başlık:</label> <input type="text" maxlength="55" name="title" id="title" /><br />
      <label>Mesaj:</label> <textarea name="message" id="message" /></textarea><br />
      <label></label><input type="button" value=" Gönder " id="sendit" class="input-submit" />
    </form>\';
      }';
    return $r;
  }

  function processEmailForm() {
    global $mysql,$SITE_CONTACT_MAIL;
    $out='';
    $title=@$_POST['title'];
    $message=@$_POST['message'];
    if (empty($title)||empty($message)) $out='Başlık ve mesaj alanlarını boş bırakmayın';
    elseif (strlen($title)<3||strlen($title)>55) $out='Başlık en az 3 en fazla 55 karakter olmalıdır';
    elseif (strlen($message)<5) $out='Mesaj en az 5 karekter olmalıdır.';
    else {
      $q=$mysql->query("select id,email from ".$this->users_table." where level>0 order by id asc");
      while ($read=$mysql->fetch($q)) {
        $email=$read['email'];
        $id=$read['id'];
        $send=sendMail($email,$SITE_CONTACT_MAIL,$title,$message);
        if (!$send) $out.="$id idli kullanıcıya e-mail gönderilemedi<br />";
      }
      if (empty($out)) $out='echo \'Tüm üyelere e-mail gönderildi\';';
      $out='echo \'<h1>E-Posta Gönder</h1><br />'.$out.goBack().'\';';
      $out='$module=@htmlspecialchars($_GET[\'module\']);
      if ($module==\'sendemail\') { '.$out.'}';
      return  $out;
    }
  }
}
/* INIT */
global $hook;
$sendEmailToMembers=new sendEmailToMembers();
if (isAdmin()) {
  $hook->addtoHook('afterAdminLeftMenu',$sendEmailToMembers->showAdminLink());
  $hook->addtoHook('modulePageBeforePost',$sendEmailToMembers->showSendForm());
  $hook->addtoHook('modulePageAfterPost',$sendEmailToMembers->processEmailForm());
}
/* /INIT */
?>